package when3meet.controller;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import when3meet.model.ClientInfo;
import when3meet.utilities.InputUtilities;
import when3meet.view.CreateEventFrame;
import when3meet.view.SignInFrame;

/**
 * GUI-based controller when CreateEventButton is clicked
 * 
 * @author Xi
 * 
 */
public class CreateEventBtnController implements ActionListener {

	SignInFrame signInFrame;
	CreateEventFrame createEventFrame;

	public CreateEventBtnController(SignInFrame sf) {

		signInFrame = sf;
		createEventFrame = CreateEventFrame.getInstance();

	}

	/**
	 * Store user name and password in local model
	 */
	public void actionPerformed(ActionEvent arg0) {

		boolean b = InputUtilities.checkTextFieldInput(signInFrame.getUserNameField());

		if (b == true) {
			ClientInfo ci = ClientInfo.getInstance();

			ci.setUserName(signInFrame.getUserNameField().getText());
			ci.setPassword(signInFrame.getPasswordField().getText());

			createEventFrame.setVisible(true);
			signInFrame.dispose();
		} else {
			signInFrame.getUserNameField().setBackground(Color.RED);
		}

	}
}
